package com.ruoyi.system.controller;

import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("system")
@CrossOrigin
public class SystemController {
    @Autowired
    private SystemService systemService;

    @RequestMapping("gai1")
    public void getSystem(@RequestBody Basicsetting basicsetting){
       systemService.update1(basicsetting);
    }
    @RequestMapping("gai2")
    public void getSystem2(@RequestBody Collectset collectset){
       systemService.update2(collectset);
    }
    @RequestMapping("gai3")
    public void getSystem3(@RequestBody Deliverysetup deliverysetup){
        systemService.update3(deliverysetup);
    }
    @RequestMapping("kan1")
    public Basicsetting getSystem(){
        return systemService.getSystem1();
    }
    @RequestMapping("kan2")
    public Collectset getSystem2(){
        return systemService.getSystem2();
    }
    @RequestMapping("kan3")
    public Deliverysetup getSystem3(){
        return systemService.getSystem3();
    }
    @RequestMapping("kan4")
    public Smartcounter getSystem4(){
        return systemService.getSystem4();
    }
    @RequestMapping("gai4")
    public void getSystem5(@RequestBody Smartcounter smartcounter){
        systemService.update4(smartcounter);
    }
    @RequestMapping("kan5")
    public List<Dropdownkey> getSystem6(){
        return systemService.getSystem6();
    }
    @RequestMapping("tianjia")
    public int tianjia(@RequestBody Dropdownkey dropdownkey){
        dropdownkey.setStatus(1);
        dropdownkey.setValue("");
        systemService.tianjia(dropdownkey);
        return 200;
    }
    @RequestMapping("xiugai")
    public int shanchu(@RequestBody Dropdownkey dropdownkey){
        systemService.xiugai(dropdownkey);
        return 200;
    }
    @RequestMapping("xiugai1")
    public int xiugai1(@RequestBody Dropdownvalue dropdownvalue) {
    System.out.println("1111111111");
    System.out.println(dropdownvalue);
    System.out.println("11111111111");
    systemService.xiugai1(dropdownvalue);
    Dropdownkey dropdownkey = systemService.cha(dropdownvalue.getDid());
    List<Dropdownvalue> dropdownvalue1 = systemService.cha2(dropdownvalue.getDid());
    dropdownkey.setDropdownvalues(dropdownvalue1);
        String v="";
        List<Dropdownvalue> dropdownvaluesr = dropdownkey.getDropdownvalues();
        for (Dropdownvalue dropdownvalues : dropdownvaluesr) {
            v=v+dropdownvalues.getValue()+",";
        }
    dropdownkey.setValue(v);
    systemService.xiugai(dropdownkey);
    return 200;
    }
    @RequestMapping("tianjia1")
    public int tianjia1(@RequestBody Dropdownvalue dropdownvalue){
        systemService.tianjia1(dropdownvalue);
        return 200;
    }
}
